/*
 * WindowListener.h
 *
 *  Created on: 2012-10-20
 *      Author: yangentao@gmail.com
 */

#ifndef WINDOWLISTENER_H_
#define WINDOWLISTENER_H_
#include "headers.h"

class MsgResult {
public:
	HRESULT hr;
	BOOL enable;
public:
	MsgResult();
	explicit MsgResult(HRESULT hr_);
};
extern MsgResult NoResult;

inline MsgResult::MsgResult() {
	enable = FALSE;
	hr = 0;
}
inline MsgResult::MsgResult(HRESULT hr_) {
	hr = hr_;
	enable = TRUE;
}

class WindowListener {
public:
	virtual ~WindowListener();
	virtual MsgResult onMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) = 0;
};

class WindowMessageListenerWraper {
public:
	WindowListener* listener;
public:
	WindowMessageListenerWraper(WindowListener* listener_ = 0);
	MsgResult operator()(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
	bool operator==(const WindowMessageListenerWraper& other);
};

inline WindowMessageListenerWraper::WindowMessageListenerWraper(WindowListener* listener_) {
	listener = listener_;
}
inline MsgResult WindowMessageListenerWraper::operator()(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	if (listener) {
		return listener->onMessage(hWnd, uMsg, wParam, lParam);
	}
	return NoResult;
}
inline bool WindowMessageListenerWraper::operator==(const WindowMessageListenerWraper& other) {
	return listener == other.listener;
}

#endif /* WINDOWLISTENER_H_ */
